package com.lanou.dllo.baisibudejie.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.lanou.dllo.baisibudejie.constant.Constant;

/**
 * Created by dllo on 15/10/22.
 */
public class MySQLliteOpenHelper extends SQLiteOpenHelper {


    public MySQLliteOpenHelper(Context context, String name,
                     SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    private static MySQLliteOpenHelper mInstance = null;



    public synchronized static MySQLliteOpenHelper getInstance(Context context, String name,
                                                               SQLiteDatabase.CursorFactory factory, int version) {
        if (mInstance == null) {
            mInstance = new MySQLliteOpenHelper(context,name,factory,version);
        }
        return mInstance;
    };

    @Override
    public void onCreate(SQLiteDatabase db) {

        String sql_user = " create table " + Constant.TABLE_NAME_USER
                + " ( " + Constant.COLUMN_USER_NAME + " varchar(255),"
                + Constant.COLUMN_USER_PASSWORD + " varchar(255),"
                + Constant.COLUMN_USER_ISLOGIN + "varchar"
                + "_msgId integer primary key autoincrement" + " ) ";
        db.execSQL(sql_user);

        String sql_mynews = " create table " + Constant.TABLE_NAME_MYNEWS
                + " ( " + Constant.COLUMN_MYNEWS_NAME + " varchar(255),"
                + Constant.COLUMN_MYNEWS_IMAGEURL + " varchar(255),"
                + Constant.COLUMN_USER_ISLOGIN + "varchar"
                + "_msgId integer primary key autoincrement" + " ) ";
        db.execSQL(sql_mynews);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
